<template>
  <div id="app">
    <div class="login_container">
      <!-- 登录盒子  -->
      <div class="login_box" style="height: 380px">
        <!-- 头像 -->
        <div class="avatar_box">
          <img src="../assets/login.png" alt="">
        </div>
        <!-- 登录表单 -->
        <el-form :model="loginForm" label-width="0px" class="login_form" @keyup.enter.native="login">
          <div style="text-align: center;padding:5px">
            <h1>自助洗车后台管理系统</h1>
          </div>
          <!-- 用户名 -->
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item prop="password">
            <el-input type="password" v-model="loginForm.password" prefix-icon="el-icon-lock"></el-input>
          </el-form-item>
          <!-- 按钮 -->
          <div style=" display: flex;justify-content: center;">
            <el-form-item class="myBtn">
              <el-button type="primary" @click="login" style="width: 100px">登录</el-button>
              <el-button type="info" style="width: 100px" @click="reset">重置</el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: "admin",
        password: "123456",
      },
    }
  },
  methods: {
    //登录接口
    login() {
      this.$http.post("/login?username=" + this.loginForm.username + "&password=" + this.loginForm.password).then((res => {
        console.log(res);

        sessionStorage.setItem("token", res.data.data);
        this.$message({
          message: res.data.msg,
          type: 'success'
        });
        this.$router.push("/show");

      })
        , errorMsg => {
          this.$message({
            message: errorMsg,
            type: 'error'
          });
        });
    },
    reset() {
      this.loginForm = {};
    },
  }
}
</script>
<style scoped>
html,
body,
#app {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
}

.login_container {
  background-image: url('../assets/login_backgroud.png');
  background-size: cover;
  background-position: center center;
  height: 100vh;
}

.login_box {
  width: 450px;
  height: 300px;
  background: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.login_box>.avatar_box {
  height: 130px;
  width: 130px;
  border: 1px solid #eee;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
}

.login_box>.avatar_box>img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #eee;
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}

.myBtn {
  display: flex;
  justify-content: flex-end;
}
</style>
